#define _CRT_SECURE_NO_WARNINGS   1

#include"Stack.h"


void StackInit(ST* st) {
	assert(st);
	st->a = NULL;
	st->capacity = 0;
	st->top = 0;


}
void StackDestroy(ST* st)
{
	assert(st);
	free(st->a);
	st->capacity = 0;
	st->top = 0;

}
// ջ
void StackPush(ST* st, StackType x)
{
	assert(st);
	if (st->top == st->capacity)
	{
		
		int newcapacity = st->capacity == 0 ? 4 : 2 * st->capacity;
		ST* tmp;
		tmp = (ST*)realloc(st,sizeof(StackType)*(st->capacity));
		if (tmp == NULL)
		{
			perror("realloc");
			return;


		}
		st->a = tmp;
		st->capacity = newcapacity;		
		st->top++;
	}
	st->a[st->top - 1] = x;
	st->top++;



}
void StackPop(ST* st)
{
	aseert(st);
	assert(st->top);
	st->top--;
}
StackType StackTop(ST* st)
{
	assert(st);
	assert(st->top);
	return st->a[st->top - 1];
}

bool Is_Empty(ST* st)
{
	assert(st);
	return st->top == 0;


}
int StackSize(ST* st)
{
	assert(st);
	return st->top;


}
